<template>
    <section class="chart-container">
        <el-row>
            <el-col :span="12">
                <div id="chartColumn" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartBar" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartLine" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="12">
                <div id="chartPie" style="width:100%; height:400px;"></div>
            </el-col>
            <el-col :span="24">
                <a href="http://echarts.baidu.com/examples.html" target="_blank" style="float: right;">more>></a>
            </el-col>
        </el-row>
    </section>
</template>

<script>
    import echarts from 'echarts'

    export default {
        data() {
            return {
                my_data:{
                    emplCountVOs:[],
                    orderPriceCountVOs:[]
                },
                chartColumn: null,
                chartBar: null,
                chartLine: null,
                chartPie: null,

                draw_option:{
                    color:[


                        '#e69d87',
                        '#8dc1a9',
                        '#ea7e53',
                        '#eedd78',
                        '#73a373',
                        '#73b9bc',
                        '#7289ab',
                        '#91ca8c',
                        '#f49f42'
                    ],
                    title: { text: '租户统计' },
                    tooltip: {},
                    xAxis: {
                        data: []
                    },
                    yAxis: {
                        //保证分割是整数
                        minInterval: 1,
                        //保证分割已什么进行分割
                        type: 'value',
                        //调整轴距的刻度大小 间距
                        axisTick: {
                            length: 6,
                            lineStyle: {
                                type: 'dashed'
                                // ...
                            },
                        },
                        //重命名自定义刻度的单位
                        axisLabel: {
                            formatter: '{value} 人数'
                        }
                    },
                    series: [{
                        name: '员工数量',
                        type: 'bar',
                        data: []
                    }]
                },

                bar_option:{


                    color:[

                        '#19ff00',
                        '#e69d87',
                        '#8dc1a9',
                        '#ea7e53',
                        '#eedd78',
                        '#73a373',
                        '#73b9bc',
                        '#7289ab',
                        '#91ca8c',
                        '#f49f42'
                    ],
                    title: {
                        text: '订单金额统计',
                        subtext: ''
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    legend: {
                        data: ['2011年', '2012年']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0,0.2]
                    },
                    yAxis: {
                        type: 'category',
                        data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)']
                    },
                    series: [
                        {
                            name: '2022年',
                            type: 'bar',
                            data: [18203, 23489, 29034, 104970, 131744, 630230]
                        }
                    ]
                }
            }
        },

        methods: {
            //获取对应的数据
            getMyData(){
                this.$http.get("/org/getConsoleData").then(res=>{

                    console.log("当前得到的数据为:============="+JSON.stringify(res.data))
                    this.my_data = res.data
                    //这里开始填充对应的数据
                    this.draw_option.xAxis.data = this.my_data.emplCountVOs.map(item => item.shopName);
                    this.draw_option.series[0].data = this.my_data.emplCountVOs.map(item => {
                        let json = {};

                        json.value =  item.emplCount
                        json.id = item.shopId
                        return json
                        //{id:shopID,value:emplCount}
                    });

                    this.chartColumn.setOption(this.draw_option);
                    this.bar_option.yAxis.data = this.my_data.orderPriceCountVOs.map(item => item.shopName);
                    this.bar_option.series[0].data = this.my_data.orderPriceCountVOs.map(item => item.priceCount);
                    this.chartBar.setOption(this.bar_option);

                })
            },

            drawColumnChart() {

                var _this = this;
                this.chartColumn = echarts.init(document.getElementById('chartColumn'));

                this.chartColumn.on('click', function(params) {
                    // 控制台打印数据的名称
                    console.log(params);
                    _this.$router.push({ path: "/empl",query: { shopId: params.data.id }})
                });
                // this.chartColumn.resize()
                //this.chartColumn.setOption(this.draw_option);

            },
            drawBarChart() {
                this.chartBar = echarts.init(document.getElementById('chartBar'));
                this.chartBar.setOption(this.bar_option);
            },
            drawLineChart() {
                this.chartLine = echarts.init(document.getElementById('chartLine'));
                this.chartLine.setOption({
                    title: {
                        text: '每月订单金额统计'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['邮件营销', '联盟广告', '搜索引擎']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            name: '邮件营销',
                            type: 'line',
                            stack: '总量',
                            data: [120, 132, 101, 134, 90, 230, 210]
                        },
                        {
                            name: '联盟广告',
                            type: 'line',
                            stack: '总量',
                            data: [220, 182, 191, 234, 290, 330, 310]
                        },
                        {
                            name: '搜索引擎',
                            type: 'line',
                            stack: '总量',
                            data: [820, 932, 901, 934, 1290, 1330, 1320]
                        }
                    ]
                });
            },
            drawPieChart() {
                this.chartPie = echarts.init(document.getElementById('chartPie'));
                this.chartPie.setOption({
                    title: {
                        text: 'Pie Chart',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: [
                                { value: 335, name: '直接访问' },
                                { value: 310, name: '邮件营销' },
                                { value: 234, name: '联盟广告' },
                                { value: 135, name: '视频广告' },
                                { value: 1548, name: '搜索引擎' }
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
            },
            drawCharts() {
                this.drawColumnChart()
                this.drawBarChart()
                this.drawLineChart()
                this.drawPieChart()
            },
        },

        mounted: function () {
            this.drawCharts()
            this.getMyData()
        },
        updated: function () {
            this.drawCharts()
        }
    }
</script>

<style scoped>
    .chart-container {
        width: 100%;
        float: left;
    }
    /*.chart div {
        height: 400px;
        float: left;
    }*/

    .el-col {
        padding: 30px 20px;
    }
</style>
